package yourapp.expense.service;

// QueryService.java 新增方法

import yourapp.expense.dao.ExpenseDAO;
import yourapp.expense.dto.StatisticsDTO;
import yourapp.expense.entity.Expense;


import java.sql.Date;
import java.util.List;

public class QueryService {
  private ExpenseDAO expenseDAO = new ExpenseDAO();
  private StatisticsService statisticsService = new StatisticsService();
  public List<Expense> queryExpensesByYear(int year) {
    return expenseDAO.getExpensesByYear(year);
  }

  public List<Expense> queryExpensesByMonth(int year, int month) {
    return expenseDAO.getExpensesByMonth(year, month);
  }

  public List<Expense> queryExpensesByDay(int year, int month, int day) {
    return expenseDAO.getExpensesByDay(year, month, day);
  }

  public List<Expense> getExpensesByDays(List<Date> dates) {
    return expenseDAO.getExpensesByDays(dates);
  }

  public StatisticsDTO calculateYearStats(int year) {
    List<Expense> expenses = queryExpensesByYear(year);
    return statisticsService.calculateStats(expenses);
  }

  public StatisticsDTO calculateMonthStats(int year, int month) {
    List<Expense> expenses = queryExpensesByMonth(year, month);
    return statisticsService.calculateStats(expenses);
  }

  public StatisticsDTO calculateWeekStats(List<Date> weekDates) {
    List<Expense> expenses = getExpensesByDays(weekDates);
    return statisticsService.calculateStats(expenses);
  }
}